package top.littlejiang.onlinexam.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import top.littlejiang.onlinexam.common.base.BaseServiceImpl;
import top.littlejiang.onlinexam.entity.OlexamStuScore;
import top.littlejiang.onlinexam.mapper.OlexamStuScoreMapper;
import top.littlejiang.onlinexam.service.OlexamStuScoreService;

import java.util.List;

/**
 * <p>
 * 学生成绩表 服务实现类
 * </p>
 *
 * @author chen
 * @since 2021-03-11
 */
@Service
public class OlexamStuScoreServiceImpl extends BaseServiceImpl<OlexamStuScoreMapper, OlexamStuScore> implements OlexamStuScoreService {

    /**
     * 根据考试id 用户id 查询试卷id
     *
     * @param examUuid
     * @param userId
     * @return
     */
    @Override
    public OlexamStuScore queryOne(String examUuid, int userId) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("fk_user_id", userId);
        wrapper.eq("fk_exam_uuid", examUuid);
        List<OlexamStuScore> list = list(wrapper);
        if (CollectionUtils.isEmpty(list)){
            return null;
        }else{
            return list.get(0);
        }
    }
}
